<template>
	<view class="container">
		<view class="user-section">
			<!-- <image class="bg" src="/static/user-bg.jpg"></image> -->
			<view class="userCard">
				<view class="user-info-box">
					<view class="portrait-box" @click="hasLogin == false && navTo('/pages/login/login')">
						<image class="portrait" @click="goUserInfo" :src="patient.avatar||'/static/missing-face.png'"></image>
					</view>
				</view>
			
				<view class="usernameText">
					<text class="username">{{ 'Hi，'+ patient.name }}</text>
				</view>
				<view class="vip-card-box">
					<view class="userinfo">患者姓名：<text style="color: red;">{{ patient.name }}</text></view>
					<view>身份证号：<text style="color: red;">{{ patientIdCard }}</text></view>
				</view>
			</view>
		</view>

		<view class="cover-container" :style="[
				{
					transform: coverTransform,
					transition: coverTransition
				}
			]" @touchstart="coverTouchstart" @touchmove="coverTouchmove" @touchend="coverTouchend">
			<!-- <image class="arc" src="/static/arc.png"></image> -->

			<view class="tj-sction" @click="goHistoryGH">
				<list-cell icon="icon-sousuo" iconColor="#61C05C" title="历史挂号"></list-cell>
			</view>
			<view class="item-section">
				<view @click="goShop">
					<list-cell icon="icon-gouwuche_" iconColor="#97B5E7" title="我的购物"></list-cell>
				</view>
				<view  @click="goHelp">
					<list-cell icon="icon-bangzhu1" iconColor="#54C4F2" title="帮助中心"></list-cell>
				</view>
				<view @click="goAbout">
					<list-cell icon="icon-xiaoxi" iconColor="#8AB4EE" title="关于我们"></list-cell>
				</view>
				<view @click="goFeedback">
					<list-cell icon="icon-bianji" iconColor="#97B5E7" title="意见反馈"></list-cell>
				</view>
			</view>
			<!-- 系统设置 -->
			<view class="setting-section icon">
				<list-cell icon="icon-shezhi1" iconColor="#97B5E7" title="系统设置" border="" @eventClick="goSet"></list-cell>
			</view>

			<view>
				<button class="login" @click="openConfirm">退出登录</button>
			</view>
		</view>
	</view>
</template>
<script>
	import listCell from '@/components/mix-list-cell';
	import {
		mapGetters
	} from 'vuex';
	let startY = 0,
		moveY = 0,
		pageAtTop = true;
	export default {
		components: {
			listCell
		},
		data() {
			return {
				patient: {},
				patientIdCard: "",
				coverTransform: 'translateY(0px)',
				coverTransition: '0s',
				moving: false,
			};
		},
		async onLoad() {
			this.patient = uni.getStorageSync('patient');
			this.patientIdCard = this.hideIdNumber(this.patient.idCard);
		},
		// #ifndef MP
		onNavigationBarButtonTap(e) {
			const index = e.index;
			if (index === 0) {
				this.navTo('/pages/set/set');
			} else if (index === 1) {
				// #ifdef APP-PLUS
				const pages = getCurrentPages();
				const page = pages[pages.length - 1];
				const currentWebview = page.$getAppWebview();
				currentWebview.hideTitleNViewButtonRedDot({
					index
				});
				// #endif
				uni.navigateTo({
					url: '/pages/notice/notice'
				});
			}
		},
		// #endif
		computed: {
			...mapGetters(['hasLogin', 'nickname', 'avatar', 'balance'])
		},
		methods: {
			hideIdNumber(id) {
			    // 身份证号码的前 6 位和后 4 位保留，中间 8 位替换为星号
			    return id.replace(/^(\d{6})\d{8}(\d{4})$/, '$1********$2');
			},
			/**
			 * 统一跳转接口,拦截未登录路由
			 * navigator标签现在默认没有转场动画，所以用view
			 */
			navTo(url) {
				console.log('跳转路径', url);
				if (!this.hasLogin) {
					url = '/pages/login/login';
				}
				uni.navigateTo({
					url
				});
			},

			/**
			 * 跳转帮助中心
			 * @param {Object} url
			 */
			goHelp() {
				uni.navigateTo({
					url: '/pages/help/index',
				})
			},

			/**
			 * 跳转关于我们
			 * @param {Object} url
			 */
			goAbout() {
				uni.navigateTo({
					url: '/pages/about/index',
				})
			},

			/**
			 * 跳转意见反馈
			 * @param {Object} url
			 */
			goFeedback() {
				uni.navigateTo({
					url: '/pages/advice/index',
				})	
			},
			/**
			 * 跳转购物车
			 * @param {Object} url
			 */
			goShop() {
				uni.navigateTo({
					url: '/pages/goods/shop',
				})	
			},
			coverTouchstart(e) {
				if (pageAtTop === false) {
					return;
				}
				this.coverTransition = 'transform .1s linear';
				startY = e.touches[0].clientY;
			},
			coverTouchmove(e) {
				moveY = e.touches[0].clientY;
				let moveDistance = moveY - startY;
				if (moveDistance < 0) {
					this.moving = false;
					return;
				}
				this.moving = true;
				if (moveDistance >= 80 && moveDistance < 100) {
					moveDistance = 80;
				}

				if (moveDistance > 0 && moveDistance <= 80) {
					this.coverTransform = `translateY(${moveDistance}px)`;
				}
			},
			coverTouchend() {
				if (this.moving === false) {
					return;
				}
				this.moving = false;
				this.coverTransition = 'transform 0.3s cubic-bezier(.21,1.93,.53,.64)';
				this.coverTransform = 'translateY(0px)';
			},
			goHistoryGH() {
				console.log(11);
				uni.navigateTo({
					url: '/pages/historyGH/index'
				})
			},
			openConfirm() {
				uni.showModal({
					title: '提示',
					content: '确定要退出登录吗？',
					success: (res) => {
						if (res.confirm) {
							console.log('用户点击确定');
							uni.clearStorageSync();
							uni.reLaunch({
								url: '/pages/login/login'
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					},
				})
			},
			goSet() {
				uni.navigateTo({
					url: '/pages/set/set',
				})
			},
			goUserInfo() {
				uni.navigateTo({
					url: '/pages/userinfo/userinfo',
				})
			},
		}
	};
</script>
<style lang="scss">
	.login {
		margin-top: 20px;
		background-color: #1AAC19;
		margin: 20px 30upx;
		color: white;
	}

	.userinfo {
		margin-bottom: 10px;
	}

	%flex-center {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}

	%section {
		display: flex;
		justify-content: space-around;
		align-content: center;
		background: #fff;
		border-radius: 10upx;
	}

	.user-section {
		height: 650upx;
		// padding: 100upx 30upx 0;
		// position: relative;
		background-color: #88CDEA;

		.bg {
			position: absolute;
			left: 0;
			top: 0;
			width: 100%;
			height: 100%;
			filter: blur(1px);
			opacity: 0.7;
		}
	}

	.user-info-box {
		height: 180upx;
		display: flex;
		align-items: center;
		z-index: 9999;
		
		.portrait {
			width: 180upx;
			height: 180upx;
			border: 5upx solid #fff;
			border-radius: 50%;
			margin: 0px 135px;
			margin-left: 118px;
			position: relative;
			top: -90upx;
			z-index: 10000;
		}

		.username {
			font-size: $font-lg + 6upx;
			color: $font-color-dark;
		}

		.icon-bianji {
			font-size: 48upx;
			color: #fff;
			position: absolute;
			right: 50px;
			top: 100px;
		}
	}

	.userCard {
		width: 330px;
		height: 172px;
		position: absolute;
		left: 30px;
		top: 30px;
		background-color: white;
		border-radius: 10px;
		margin-top: 35px;
	}

	.usernameText {
		text-align: center;
		margin-top: -35px;
	}

	.vip-card-box {
		display: flex;
		flex-direction: column;
		// color: #f7d680;
		height: 240upx;
		background: linear-gradient(left, rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.8));
		border-radius: 16upx 16upx 0 0;
		overflow: hidden;
		position: relative;
		padding: 20upx 30px;

		.card-bg {
			position: absolute;
			top: 20upx;
			right: 0;
			width: 380upx;
			height: 260upx;
		}

		.b-btn {
			position: absolute;
			right: 20upx;
			top: 16upx;
			width: 132upx;
			height: 40upx;
			text-align: center;
			line-height: 40upx;
			font-size: 22upx;
			color: #36343c;
			border-radius: 20px;
			background: linear-gradient(left, #f9e6af, #ffd465);
			z-index: 1;
		}

		.tit {
			font-size: $font-base + 2upx;
			color: #f7d680;
			margin-bottom: 28upx;

			.yticon {
				color: #f6e5a3;
				margin-right: 16upx;
			}
		}

		.e-b {
			font-size: $font-sm;
			color: #d8cba9;
			margin-top: 10upx;
		}
	}

	.cover-container {
		background: $page-color-base;
		margin-top: -150upx;
		// padding: 0 30upx;
		position: relative;
		background: #f5f5f5;
		padding-bottom: 20upx;

		.arc {
			position: absolute;
			left: 0;
			top: -34upx;
			width: 100%;
			height: 36upx;
		}
	}

	.tj-sction {
		// @extend %section;
		background: #fff;

		.tj-item {
			@extend %flex-center;
			flex-direction: column;
			height: 140upx;
			font-size: $font-sm;
			color: #75787d;
		}

		.num {
			font-size: $font-lg;
			color: $font-color-dark;
			margin-bottom: 8upx;
		}
	}

	.item-section {
		background: #fff;
		margin-top: 20upx;

		.tj-item {
			@extend %flex-center;
			flex-direction: column;
			height: 140upx;
			font-size: $font-sm;
			color: #75787d;
		}

		.num {
			font-size: $font-lg;
			color: $font-color-dark;
			margin-bottom: 8upx;
		}
	}

	.setting-section {
		margin-top: 20upx;
		background: #fff;
		border-radius: 10upx;

		.sec-header {
			display: flex;
			align-items: center;
			font-size: $font-base;
			color: $font-color-dark;
			line-height: 40upx;
			margin-left: 30upx;

			.yticon {
				font-size: 44upx;
				color: #5eba8f;
				margin-right: 16upx;
				line-height: 40upx;
			}
		}

		.h-list {
			white-space: nowrap;
			padding: 30upx 30upx 0;

			image {
				display: inline-block;
				width: 160upx;
				height: 160upx;
				margin-right: 20upx;
				border-radius: 10upx;
			}
		}
	}
</style>